package com.woniu.listenner;

import com.woniu.been.entity.UserOrders;
import com.woniu.been.entity.Users;
import com.woniu.service.UserOrdersService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component

public class PayStatusListener {
    @Autowired
    private UserOrdersService orderService;


    // 监听delay.queue队列.
    @RabbitListener(queues = "real.queue")
    public void listenOrderPay(UserOrders userOrders){
        List<UserOrders> orders =orderService.findOrderByNumber(userOrders.getOrderNumber());

        for(UserOrders order:orders){
            System.out.println("查到的订单"+order.toString());
            if(order.getPaymentStatus().equals("待付款")) {

                orderService.updateByNumber(order.getOrderNumber());
                System.out.println("取消订单成功"+userOrders.toString());
            }else{
                System.out.println("没有查到未支付订单");
            }
        }

    }
}
